package com.drools.drools.timer;

import com.drools.drools.BaseTest;
import com.drools.drools.model.Server;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;

/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2019-05-06
 * Time: 21:58
 * Des:
 */
public class TimerTest extends BaseTest{
    @Test
    public void test() throws InterruptedException {


        KieSession kieSession=this.getKieSessionBySessionName("timerTest-rules");

        Server server=new Server();
        server.setTimes(0);
        new Thread(new Runnable() {
            @Override
            public void run() {
                //阻塞
                kieSession.fireUntilHalt();
            }
        }).start();
        FactHandle factHandle=kieSession.insert(server);
        for(int i=1;i<10;i++){
            Thread.sleep(1000);
            server.setTimes(i);
            kieSession.update(factHandle,server);
        }
        Thread.sleep(1000);
        kieSession.halt();//释放
        System.out.println(server.getResult());
        kieSession.fireAllRules();
        kieSession.dispose();
    }
}
